//
//  AppModel.m
//  VideoExam
//
//  Created by apple on 2020/5/8.
//

#import "AppModel.h"

@implementation AppModel




//获取当前用户未完成订单信息
+ (void)get_not_finished_Order_Success:(ObjSuccess)success error:(ErrorBlock)errorBlock {
    
    [NetWorkTools requestWithURLStr:get_Not_Finished_Order_url method:GET params:nil success:^(id responseObject) {
        NSLog(@"获取当前用户未完成订单信息 %@",responseObject);

        if ([AppTools is_parsing_security_responseObject:responseObject] && [AppTools isStateSuccess:responseObject]) {
            NSDictionary *data = responseObject[@"data"];
           NSString *orderId=data[@"orderId"];
           if (success) {
               success(orderId);
           }
        } else {
            if (errorBlock) {
                errorBlock();
            }
        }
    } failure:^(NSError *error) {
        NSLog(@"获取当前用户未完成订单信息error %@",error);
        NSString *errorStr = [self errorDescribe:error];
        [QMUITips showError:errorStr];
    }];
}

/// 是否强制更新
/// @param success Version_Model
/// @param errorBlock errorBlock
+(void)is_mandatory_update_Success:(ObjSuccess)success error:(ErrorBlock)errorBlock {
    [NetWorkTools requestWithURLStr:version_update_url method:GET params:nil success:^(id responseObject) {
        NSLog(@"版本信息 %@",responseObject);
        if ([AppTools isStateSuccess:responseObject]) {
            Version_Model *model = [Version_Model yy_modelWithJSON:responseObject[@"data"]];
            if (success) {
                success(model);
            }
        }
    } failure:^(NSError *error) {
        if (errorBlock) {
            errorBlock();
        }
        NSLog(@"版本信息error %@",error);
//        NSString *errorStr = [self errorDescribe:error];
//        [QMUITips showError:errorStr];
    }];
}

//获取版本信息
+(void)click_get_versin_info_Success:(ObjSuccess)success error:(ErrorBlock)errorBlock {
    [NetWorkTools requestWithURLStr:version_update_url method:GET params:nil success:^(id responseObject) {
        NSLog(@"版本信息 %@",responseObject);
        if ([AppTools isStateSuccess:responseObject]) {
            Version_Model *model = [Version_Model yy_modelWithJSON:responseObject[@"data"]];
            if (success) {
                success(model);
            }
        } else {
           if (errorBlock) {
               errorBlock();
           }
        }
    } failure:^(NSError *error) {
        if (errorBlock) {
            errorBlock();
        }
        NSLog(@"版本信息error %@",error);
        NSString *errorStr = [self errorDescribe:error];
        [QMUITips showError:errorStr];
    }];
}

/// 是否显示版本更新选项按钮，提交审核的时候隐藏
/// @param success 是禁用 1 是启用
/// @param errorBlock errorBlock
+ (void)is_Show_versin_update_Success:(ObjSuccess)success error:(ErrorBlock)errorBlock  {
     [NetWorkTools requestWithURLStr:is_show_update_btn_url method:GET params:nil success:^(id responseObject) {
            NSLog(@"是否显示版本更新 %@",responseObject);
             if ([AppTools isStateSuccess:responseObject]) {
                  NSArray * array = [NSArray yy_modelArrayWithClass:[Control_Model class] json:responseObject[@"data"]];
                     for (Control_Model *model in array) {
                         if ([model.name isEqualToString:@"UPDATE_BUTTON"]) {
                            if (success) {
                                success(model.status);
                             }
                         }
                         return;
                     }
             } else {
                 if (errorBlock) {
                     errorBlock();
                 }
             }
        } failure:^(NSError *error) {
            if (errorBlock) {
                errorBlock();
            }
            NSLog(@"是否显示版本更新error %@",error);
            NSString *errorStr = [self errorDescribe:error];
            [QMUITips showError:errorStr];
        }];
}
@end



@implementation Control_Model


@end


@implementation Version_Model

@end
